from rest_framework import serializers
from .models import DriverAccount, TransactionRecord

class DriverAccountSerializer(serializers.ModelSerializer):
    available_balance = serializers.SerializerMethodField()
    
    class Meta:
        model = DriverAccount
        fields = ['driver_id', 'balance', 'frozen_amount', 'available_balance', 'status', 'updated_at']
    
    def get_available_balance(self, obj):
        return obj.balance - obj.frozen_amount

class TransactionRecordSerializer(serializers.ModelSerializer):
    transaction_type_name = serializers.CharField(source='get_transaction_type_display')
    
    class Meta:
        model = TransactionRecord
        fields = [
            'id', 'transaction_type', 'transaction_type_name', 
            'amount', 'balance', 'transaction_time', 'remark', 'order_id'
        ]